package com.sugon.controller.module;

import com.sugon.annotation.AutoLog;
import com.sugon.annotation.DataFilter;
import com.sugon.entity.ModuleSpDeptStockEntity;
import com.sugon.service.ModuleSpDeptStockService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 车间型芯库存状态统计Controller
 *
 * @author sugon
 * @date 2022-07-07 17:05:34
 */
@Controller
@RequestMapping("modulespdeptstock")
public class ModuleSpDeptStockController {
    @Autowired
    private ModuleSpDeptStockService moduleSpDeptStockService;

    /**
     * 查看列表
     */
    @DataFilter(deptAlias = "MSDS.WORKSHOP")
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ModuleSpDeptStockEntity> moduleSpDeptStockList = moduleSpDeptStockService.queryList(query);
        int total = moduleSpDeptStockService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(moduleSpDeptStockList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        ModuleSpDeptStockEntity moduleSpDeptStock = moduleSpDeptStockService.queryObject(id);

        return R.ok().put("moduleSpDeptStock", moduleSpDeptStock);
    }

    /**
     * 保存
     */
    @AutoLog("车间型芯库存状态统计--保存")
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody ModuleSpDeptStockEntity moduleSpDeptStock) {
        moduleSpDeptStockService.save(moduleSpDeptStock);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("车间型芯库存状态统计--修改")
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody ModuleSpDeptStockEntity moduleSpDeptStock) {
        moduleSpDeptStockService.update(moduleSpDeptStock);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("车间型芯库存状态统计--删除")
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        moduleSpDeptStockService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ModuleSpDeptStockEntity> list = moduleSpDeptStockService.queryList(params);

        return R.ok().put("list", list);
    }
}
